package com.example.housingRentalSystem.controller;

import com.example.housingRentalSystem.bean.House;
import com.example.housingRentalSystem.service.CollectService;
import com.example.housingRentalSystem.utils.ApiResponse;
import com.example.housingRentalSystem.utils.PageRequest;
import com.example.housingRentalSystem.utils.PageResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 王硕
 */
@RestController
@RequestMapping("api/collect")
public class CollectController {
    @Autowired
    private CollectService collectService;

    @PostMapping("/collectHouse/{houseId}/{userId}")
    public ApiResponse<Boolean> collectHouse(
            @PathVariable Integer houseId,
            @PathVariable Integer userId) {
        boolean result = collectService.toggleCollect(userId, houseId);
        return ApiResponse.success(result ? "收藏成功" : "已取消收藏", result);
    }

    @GetMapping("/getCollectList/{userId}")
    public ApiResponse<PageResponse<House>> getCollectList(
            @PathVariable Integer userId,
            @ModelAttribute PageRequest pageRequest) {
         return ApiResponse.success(collectService.getCollectList(userId, pageRequest));
    }

    @GetMapping("/checkCollectStatus/{houseId}/{userId}")
    public ApiResponse<Boolean> checkCollectStatus(
            @PathVariable Integer houseId,
            @PathVariable Integer userId) {
        return ApiResponse.success(collectService.isCollected(userId, houseId));
    }

}
